#!/usr/bin/env python3
"""
检查数据库结构
"""

import sqlite3

def check_database_structure():
    """检查数据库表结构"""
    print("🔍 检查数据库表结构")
    print("=" * 40)
    
    try:
        conn = sqlite3.connect('data/research.db')
        cursor = conn.cursor()
        
        # 检查task_executions表结构
        print("📋 task_executions表字段:")
        cursor.execute('PRAGMA table_info(task_executions)')
        columns = cursor.fetchall()
        for col in columns:
            print(f"  • {col[1]} ({col[2]})")
        
        # 检查experiment_designs表结构
        print(f"\n🧪 experiment_designs表字段:")
        cursor.execute('PRAGMA table_info(experiment_designs)')
        columns = cursor.fetchall()
        for col in columns:
            print(f"  • {col[1]} ({col[2]})")
        
        # 检查一条task_executions记录的实际字段
        print(f"\n📊 task_executions表示例数据:")
        cursor.execute('SELECT * FROM task_executions LIMIT 1')
        task = cursor.fetchone()
        if task:
            cursor.execute('PRAGMA table_info(task_executions)')
            columns = cursor.fetchall()
            for i, col in enumerate(columns):
                value = task[i] if i < len(task) else 'NULL'
                print(f"  {col[1]}: {value}")
        else:
            print("  没有数据")
        
        conn.close()
        
    except Exception as e:
        print(f"❌ 数据库检查失败: {e}")

if __name__ == '__main__':
    check_database_structure()